package com.LC.DAO;

import com.LC.Entity.Order;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.Map;

@Mapper
public interface OrderDAO {
    
    @Select("select count(*) from t_ordersetting where orderDate = STR_TO_DATE(#{orderDate},'%Y-%m-%d')")
    public int findOrderDate(String orderDate);
    
    @Select("select reservations from t_ordersetting where orderDate = STR_TO_DATE(#{orderDate},'%Y-%m-%d')")
    public int findReservation(String orderDate);

    @Select("select number from t_ordersetting where orderDate = STR_TO_DATE(#{orderDate},'%Y-%m-%d')")
    public int findNumber(String orderDate);
    
    @Select("select * from t_order where id = #{id}")
    public Order findOrderById(int id);
    
    @Select("select count(*) from t_order where memberId = #{memberId} and orderDate = STR_TO_DATE(#{orderDate},'%Y-%m-%d') and setmealId = #{setMealId}")
    public int findRepeatOrderCount(@Param("memberId") int memberId, @Param("orderDate") String orderDate, @Param("setMealId") int setMealId);
    
    @Insert("insert into t_order values(null,#{member_id},#{memberName},#{gender},#{telephone},#{idCard},#{orderDate},#{setmealId},#{fileNumber},#{setmealName},#{orderType},#{orderStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void AddOrder(Map map);
    
    @Select("select * from t_order where memberId = #{memberId}")
    public int findOrderIdByMemberId(int memberId);
    
    @Select("select id from t_order where memberId = #{member_id} and orderDate = STR_TO_DATE(#{orderDate},'%Y-%m-%d') and " +
      "setmealId = #{setmealId}")
    public int findOrderIdByCondition(Map map);

    @Select("<script>" +
      "select * from t_order" +
      "<if test = 'value != null and value.length > 0'>" +
      "where memberName = #{value} or fileNumber = #{value}" + "</if>" +
      "</script>"
    )
    public Page<Order> findPage(String queryString);

    @Insert("insert into t_order values(null,#{memberId},#{memberName},#{gender},#{orderDate},#{setmealId},#{fileNumber},#{setmealName},#{orderType},#{orderStatus})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    public void AddBKOrder(Order order);
    
    /*@Update("update t_order set orderDate = #{orderDate},setmealId = #{setmealId},setmealName = #{setmealName}," +
            "orderType = #{orderType},orderStatus = #{orderStatus} ")
    public void UpdateBKOrder(Order order);*/
}
